<script setup lang="ts">
import type { PropType } from 'vue';
import { ref } from 'vue';
import Dialog from './edit-template-dialog.vue';
import { certificateType, certificateStatus } from '../const'

defineOptions({ name: 'Query' });
defineProps({
  modelValue: {
    type: Object as PropType<ModelValueType>,
    required: true,
  },
});

const emit = defineEmits(['update:modelValue', 'queryData', 'resetQuery']);

interface ModelValueType {
  name: string;
  type: any,
  // status: any,
  createTime: any
}

interface ModelValueType { }

const dialogRef = ref<InstanceType<typeof Dialog> | null>(null);

const onAdd = () => {
  dialogRef.value?.inint();
};

const onQueryData = () => {
  emit('queryData');
};
const resetQuery = () => {
  emit('resetQuery',)
}
</script>
<template>
  <section>
    <el-form :inline="true"
      label-width="70px"
      class="w-full border-b border-color:#DCDFE6 after:content-[''] mb-[15px] after:clear-both after:block">
      <el-form-item :label="$t('certificateTemplate.certificateNameTxt')">
        <el-input :maxlength="50" v-model="modelValue.name" clearable style="width:  100%;"
          :placeholder="$t('common.inputPhTxt', [$t('certificateTemplate.certificateNameTxt')])" />
      </el-form-item>
      <el-form-item :label="$t('certificateTemplate.certificateTypeTxt')">
        <el-select style="width:  100%;" filterable clearable v-model="modelValue.type"
          :placeholder="$t('common.selectPhTxt', [$t('certificateTemplate.certificateTypeTxt')])">
          <el-option v-for="item in certificateType" :key="item.type" :label="item.name" :value="item.type" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item :label="$t('certificateTemplate.certificateStatusTxt')">
        <el-select style="width:  100%;" filterable clearable v-model="modelValue.status" :placeholder="$t('common.selectPhTxt', [$t('certificateTemplate.certificateStatusTxt')])">
          <el-option v-for="item in certificateStatus" :key="item.status" :label="item.name" :value="item.status" />
        </el-select>
      </el-form-item> -->
      <el-form-item :label="$t('common.createTimeTxt')">
        <el-date-picker v-model="modelValue.createTime" type="daterange"
          :range-separator="$t('common.rangeSeparatorTxt')" style="width: 100%" value-format="YYYY-MM-DD HH:mm:ss"
          :unlink-panels="true" :default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)]"
          :start-placeholder="$t('common.startTimeTxt')" :end-placeholder="$t('common.endTimeTxt')" />
      </el-form-item>
      <el-form-item label="" class="float-right">
        <div class="w-full flex justify-end">
          <el-button @click="resetQuery">{{ $t('common.resetTxt') }}</el-button>
          <el-button type="primary" @click="onQueryData">{{ $t('common.searchTxt') }}</el-button>
        </div>
      </el-form-item>
    </el-form>
    <div class="opt mb-[10px]">
      <el-button type="primary" @click="onAdd">{{ `${$t('common.newTxt')}` }}</el-button>
    </div>
    <Dialog ref="dialogRef" @query-table="onQueryData" />
  </section>
</template>
<style lang="scss" scoped>
:deep(.el-form--inline .el-form-item) {
  margin-right: 24px;
  width: calc((100% - 72px)/4);

  &:nth-of-type(4n),
  &:last-of-type {
    margin-right: 0px;
  }
}

:deep(.el-form-item__label) {
  padding-right: 12px;
}

:deep(.el-date-editor .el-range__icon) {
  display: none;
}
</style>
